// This file implements the classes defined in CDPPRSObjDriver.h
// Copy right (c) 2003,6, SafeKing Software Co. L.T.D.
// Implemented by SafeKing Software Group

#ifndef _LINUX_OS_
#include "Stdafx.h"
#endif
#include "DAPSystem.h"
#include "DAPInterface.h"
#include "DAPAppDriver.h"
/////////////////////////////////////////////////////////////////////////////////
// Implement CDAPAppDriver
//
CDAPAppDriver :: CDAPAppDriver()
{
	m_pDAPSystem=NULL;
	m_nRSID=0;
	m_bInDebug=false;
	m_stsRunning=DAP_APP_QUITED;
	m_bForceSendTimeSync=false;
}
bool CDAPAppDriver :: IsRunning()
{
	return  m_stsRunning!=DAP_APP_QUITED;
}
void  CDAPAppDriver :: SetAppControlWord(CDAPAppControl &appControl, unsigned short wUserControl)
{
	m_dwAppControl.m_nEnableLocalHMI=appControl.m_nEnableLocalHMI;
	m_dwAppControl.m_nEnableRedundantCPU=appControl.m_nEnableRedundantCPU;
	m_dwAppControl.m_nEnableRedundantCH=appControl.m_nEnableRedundantCH;
	m_dwAppControl.m_nEnableMultiServer=appControl.m_nEnableMultiServer;
	m_dwAppControl.m_nEnableDA=appControl.m_nEnableDA;
	m_dwAppControl.m_nEnableHSDBB=appControl.m_nEnableHSDBB;
	m_dwAppControl.m_nEnableBatch=appControl.m_nEnableBatch;

	m_dwAppControl.m_nTotalVQCTRNo=appControl.m_nTotalVQCTRNo;
	m_dwAppControl.m_nTotalAppNo=appControl.m_nTotalAppNo;
	m_dwAppControl.m_nTotalDCAProtocol=appControl.m_nTotalDCAProtocol;
	m_dwAppControl.m_nTotalServerProtocol=appControl.m_nTotalServerProtocol;
	m_dwAppControl.m_nTotalVPortNo=appControl.m_nTotalVPortNo;
	m_dwAppControl.m_nTotalRemoteHMIClientNo=appControl.m_nTotalRemoteHMIClientNo;
	m_dwAppControl.m_nTotalExtendedHMIClientNo=appControl.m_nTotalExtendedHMIClientNo;
	m_dwAppControl.m_nEnableSMSNotify=appControl.m_nEnableSMSNotify;
	m_dwAppControl.m_nEnablePKAService=appControl.m_nEnablePKAService;
	m_dwAppControl.m_nEnableRMSManager=appControl.m_nEnableRMSManager;
	m_wUserControl=wUserControl;
}
bool CDAPAppDriver :: IsInDebug()
{
	return m_bInDebug;
}
void CDAPAppDriver :: SetDeugMode(bool bInDebug)
{
	m_bInDebug=bInDebug;
}
void CDAPAppDriver :: SetPSDValue(MGID nMGID, PTNO nPTNo, DAPValue uValue, DAPValueType nType)
{
	if(m_pDAPSystem==0)
		return;
	CDAPQuality qosValue;
#ifdef _DAP_CORE_
	m_pDAPSystem->SetEngValue(MAKEGLPTID(m_nRSID,nMGID,DAP_PSD_POINT,nPTNo), 0, uValue, nType, 0, qosValue, false,m_pDAPSystem->m_bIsMachineB);
#else
	m_pDAPSystem->SetEngValue(MAKEGLPTID(m_nRSID,nMGID,DAP_PSD_POINT,nPTNo), 0, uValue, nType, 0, qosValue, false);
#endif
}
void CDAPAppDriver :: SetRuntimeStatus(CDPPRunningStatus stsRunning)
{
	if(m_pDAPSystem==0)
		return;
	DAPValue uValue;
	uValue.nValue=stsRunning;
	CDAPQuality qosValue;
#ifdef _DAP_CORE_
	m_pDAPSystem->SetEngValue(MAKEGLPTID(m_nRSID,0,DAP_PSD_POINT,DAP_PSDRS_RNSTATUS), 0, uValue, DAP_INTEGER_TYPE, 0, qosValue, false,m_pDAPSystem->m_bIsMachineB);
#else
	m_pDAPSystem->SetEngValue(MAKEGLPTID(m_nRSID,0,DAP_PSD_POINT,DAP_PSDRS_RNSTATUS), 0, uValue, DAP_INTEGER_TYPE, 0, qosValue, false);
#endif
	m_stsRunning=stsRunning;
}
void CDAPAppDriver :: InsertSystemEvent(MGID nMGID, PTNO nEventCode, CDAPString szAlarmLevel, CDAPString szSubType, CDAPString szContents, bool bLogDatabase)
{
	if(m_pDAPSystem==0)
		return;
	m_pDAPSystem->InsertSystemEvent(m_nRSID, nMGID, nEventCode, szAlarmLevel, szSubType, szContents,bLogDatabase);
}
bool CDAPAppDriver :: Initialize(RSID nRSID, CDAPInterface *pCDPPSystem,CDAPString &szErrorCode)
{
	m_nRSID=nRSID;
	m_pDAPSystem=pCDPPSystem;
	return true;
}
void CDAPAppDriver :: SetEngValue(GLPTID nGLPTID, PTNO nPTNo, DAPValue uValue, DAPValueType nType, unsigned char nValueType, CDAPQuality qosValue, bool bManualSetFlag,bool bMachineB, CDAPTaggingStatus tagStatus, bool bUpdateTagStatus)
{
	if(m_pDAPSystem==0)
		return;
	m_pDAPSystem->SetEngValue(nGLPTID, nPTNo, uValue, nType, nValueType, qosValue, bManualSetFlag,bMachineB,tagStatus, bUpdateTagStatus);
}
void CDAPAppDriver :: SetEngValue(GLPTID nGLPTID, PTNO nPTNo, CDAPTime tmAssTime, DAPValue uValue, DAPValueType nType, unsigned char nValueType,CDAPQuality qosValue, bool bManualSetFlag, bool bMachineB, CDAPTaggingStatus tagStatus, bool bUpdateTagStatus)
{
	if(m_pDAPSystem==0)
		return;
	m_pDAPSystem->SetEngValue(nGLPTID, nPTNo, tmAssTime, uValue, nType, nValueType, qosValue, bManualSetFlag,bMachineB,tagStatus, bUpdateTagStatus);
}
